package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import entity.Exam_info;

public class Exam_info_import {
	String FORNAME="com.mysql.cj.jdbc.Driver";
	String url="jdbc:mysql://localhost:3306/ems?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false";
	
    String user="root";
    String pwd="1234";
    public Exam_info_import()
    {
        try{
            Class.forName(FORNAME);
        }catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
    }
    public Connection getConnection() throws SQLException
    {
        return  DriverManager.getConnection(url,user,pwd);
    }
    public List<Exam_info> examinfolist(String sql) throws SQLException
    {
        List<Exam_info> examinfo=new ArrayList<>();
        Connection c=getConnection();
        PreparedStatement ps=c.prepareStatement(sql);
        ResultSet rs=ps.executeQuery();
        while(rs.next())
        {
        	Exam_info ei=new Exam_info();
        	ei.setStatus(rs.getString("status").trim());
        	ei.setPeriod(rs.getString("period").trim());
        	ei.setCollege(rs.getString("college").trim());
        	ei.setCourse(rs.getString("course").trim());
        	ei.setClasses(rs.getString("classes").trim());
        	ei.setDate(rs.getString("date").trim());
        	ei.setExamTime(rs.getString("examTime").trim());
        	ei.setLocation(rs.getString("location").trim());
        	ei.setTeacher(rs.getString("teacher").trim());
        	ei.setTeacherRequire(rs.getInt("teacherRequire"));
            examinfo.add(ei);
        }
        ps.close();
        c.close();
        return examinfo;
    }
}
